import java.util.concurrent.atomic.AtomicInteger;

public class ThreadDemo7 {
    private static AtomicInteger integer=new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        Thread t1= new Thread(()->{
           for(int i=0;i<50000;i++){
               integer.getAndIncrement();
           }
        });

        Thread t2= new Thread(()->{
            for(int i=0;i<50000;i++){
                integer.getAndIncrement();
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(integer.get());


    }

}
//class AtomicInteger{
//    private int value;
//    public int getAndIncrement(){
//        int oldvalue=value;
//        while(CAS(value,oldValue,oldValue+1)!= true){
//            oldValue=value;
//        }
//        return value;
//    }
//}
